package com.csi.service.impl;

import com.csi.dao.CommentDao;
import com.csi.dao.impl.CommentDaoImpl;
import com.csi.domain.Comment;
import com.csi.service.CommentService;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CommentServiceImpl  implements CommentService {


    @Override
    public int add(Comment comment) {
        CommentDao commentDao =new CommentDaoImpl();

        int i = 0;
        try {
            i = commentDao.add(comment);
        } catch (SQLException e) {
            e.printStackTrace();
        }


        return i;
    }

    @Override
    public int delete(int commentId) {

        CommentDao commentDao =new CommentDaoImpl();

        int i = 0;
        try {
            i = commentDao.delete(commentId);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return i;
    }

    @Override
    public int update(Comment comment) {
        CommentDao commentDao =new CommentDaoImpl();

        int i = 0;
        try {
            i = commentDao.update(comment);
        } catch (SQLException e) {
            e.printStackTrace();
        }


        return i;
    }

    @Override
    public List<Comment> list(int indexPage, int title) {
        CommentDao commentDao =new CommentDaoImpl();

        List<Comment> list =new ArrayList<>();
        try {
            list = commentDao.list(indexPage, title);
        } catch (SQLException e) {
            e.printStackTrace();
        }


        return list;
    }
}
